<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<style>
    .bootbox-close-button {
        width: 19px;
        height: 19px;
        border: none;
        cursor: pointer;
        -webkit-appearance: none;
        float: right;
        top: 4px;
        left: -5px;
        position: relative;
        background: #E9F5FF url("assets/img/nav-img/icon_close.png") no-repeat 0 0;
    }

    .bootbox .modal-dialog {
        width: 50% !important;
    }

    .modal-content {
        width: 100%;
    }

    input, select, .form-control {
        height: 30px;
    }

    .myDialogDetail label {
        margin-bottom: 0px !important;
    }
    th,td{
        height: 34.29px!important;
    }

    .detailDialogStyle {
        line-height: 30px;
        margin-bottom: 15px;
    }
    .myDialogDetail1 .modal-body{
        padding-bottom: 0px!important;
        border-bottom-right-radius: 5px!important;
        border-bottom-left-radius: 5px!important;
    }
    #tssMemberAddRecordEditHtml label{
        margin-bottom: 0px!important;
        line-height: 30px;
    }
</style>
<div class="row" id="tssMemberAddRecordEditDiv">
    <label class="businessBtns col-lg-12 col-sm-12 col-xs-12 col-sm-offset-4 margin-top-20">
        <a type="btn" class="btn chooseDetailBtn" serializeNum="${serializeNum}" editUrl="${editUrl}" addSubtractType="1"
           onclick="showDialogAddSubtract(this);"
           style="background-color: #23a8f5;border: none;border-top-left-radius: 4px!important;border-bottom-left-radius: 4px!important;width: 120px;color: #fff;margin-right: 0!important;box-shadow:0px 0px 10px rgba(122,161,184,0.3);">
            加
        </a><a type="btn" class="btn chooseDetailBtn"  serializeNum="${serializeNum}" addSubtractType="2"
               onclick="showDialogAddSubtract(this);"
               style="border: none;border-top-right-radius: 4px!important;border-bottom-right-radius: 4px!important;width: 120px;color: #4a647d;box-shadow:0px 0px 10px rgba(122,161,184,0.3);">
        减
    </a>
    </label>
    <div id="tssMemberAddRecordEditHtml">
        <div class="col-lg-12 col-sm-12 col-xs-12 tssMemberAddRecordDiv1 tssMemberAddRecordDiv">
            <form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form"
                  id="addEditForm_${serializeNum}"
                  data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
                  data-bv-message="This value is not valid"
                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                <input type="hidden" name="id" value="${editEntity.id}">
                <input type="hidden" name="memberPackageId" value="${memberPackageId}" class="memberPackageId">
                <input type="hidden" name="addSubtractType" value="1">
                <#if (true && editModel=='add')||(true && editModel=='edit')>
                    <div class="col-xm-12 col-sm-6 col-lg-12 margin-top-30">
                        <div class="form-group">
                            <label for="addClassHour" class="col-sm-2 col-sm-offset-1 control-label no-padding-right">加课时数（赠课）:</label>
                            <div class="col-sm-3">
                                <input data-bv-integer-message="The field is number" size="11"
                                       data-bv-message="The field is not valid" data-bv-integer="true" maxlength="3"
                                       name="classHour" alt="加课时数" id="addClassHour" placeholder="加课时数" type="text"
                                       title="加课时数" class="form-control" value="${editEntity.addClassHour}"/>
                                <span class="text"></span>
                            </div>
                            <label class="control-label">课时 <span style="margin-left:30px">剩余${data.surplusPresentClassHour}赠课</span><span style="margin-left: 30px">（不计入权责）</span></label>
                        </div>
                    </div>
                </#if>
                <#if (true && editModel=='add')||(true && editModel=='edit')>
                    <div class="col-xm-12 col-sm-6 col-lg-12">
                        <div class="form-group">
                            <label  class="col-sm-2 col-sm-offset-1 control-label no-padding-right">备注：</label>
                            <div class="col-sm-8">
                        <textarea class="form-control" name="remark"  rows="3" style="resize:none" maxlength="499"
                                  id="remark" data-bv-field="remark" value="${editEntity.remark}"></textarea>
                            </div>
                        </div>
                    </div>

                </#if>
                <div class="col-sm-12 text-align-center margin-top-20 ">
                    <button style="width: 80px;margin-right: 20px" type="submit" class="btn btn-blue" id="editFormSubmitBtn_${serializeNum}">确定</button>
                    <input style="width: 80px;" type="button" class="btn btn-blue" data-dismiss="modal" value="取消" />

                </div>
            </form>
            <!--<span>剩余赠课 ${data.surplusPresentClassHour}</span>-->
        </div>
    </div>
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
    $(".selectpicker_${serializeNum}").select2()
    $("#addEditForm_${serializeNum}").bind("ajaxSubmitCallback", function (event, result) {
        if (result.resCode == 200) {
            bootbox.hideAll();
            logger.info("保存成功", true);
        } else {
            logger.error("保存失败");
        }
    });
    function verificationNumber(that) {
        var max = $(that).attr("data-max");
        var thatVal = $(that).val();
        if(Number(thatVal) > Number(max)){
            $(that).val("")
            logger.error("课时数需要小于剩余课时数");
        }
    }
    
    function showDialogAddSubtract(that) {
        var serializeNum = $(that).attr("serializeNum");
        var addSubtractType=$(that).attr("addSubtractType");
        var memberPackageId=$(".memberPackageId").val();
        $(".chooseDetailBtn").each(function () {
            if ($(this).attr("addSubtractType") == addSubtractType) {
                $(this).css("background-color", "#23a8f5");
                $(this).css("color", "#fff");
            } else {
                $(this).css("background-color", "#fff");
                $(this).css("color", "#4a647d");
            }
        })

        ajaxRequest("tssMemberAddSubtractRecordController/toEditView.do", {
            memberPackageId:memberPackageId,
            serializeNum: serializeNum,
            addSubtractType:addSubtractType,
            type:1
        }, function (html) {
            var size = $("#tssMemberAddRecordEditHtml").find(".tssMemberAddRecordDiv" + addSubtractType).size();
            if(addSubtractType==1){
                $(".tssMemberSubtractRecordDialog #tssMemberAddRecordEditDiv").remove();
                $(".tssMemberSubtractRecordDialog .bootbox-body").append(html);
            }else{
                if (size == 0) {
                    $("#tssMemberAddRecordEditHtml").append(html);
                    $("#tssMemberAddRecordEditHtml").find(".tssMemberAddRecordDiv").each(function () {
                        if ($(this).attr("class").split(" ").indexOf("tssMemberAddRecordDiv" + addSubtractType) < 0) {
                            $(this).remove();
                        }
                    })
                }
            }

        }, function () {
            ajaxError("加载页面失败!")
        }, "get", "html")

    }
</script>